package de.hm.edu.cep;

import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;

/**
 * This class represents an order event
 * 
 * @author Peter Goldenbogen (Munich University of Applied Science)
 * @version 1.0
 */
public class OrderEvent {
	
	private UUID id;
	/**A list of events that directly caused the event to happen*/
	private final ArrayList<UUID> causality = new ArrayList<>();
	/**actual system time when the event was created*/
	private Date timestamp;
	/**The product that has been ordered */
	private String product;
	/**The amount of products that has been ordered */
	private int amount;

	public OrderEvent(){
		super();
		this.id = UUID.randomUUID();
		this.timestamp = new Date(System.currentTimeMillis());
	}
	
	public OrderEvent(String product, int amount, ArrayList<UUID> causality){
		super();
		this.id = UUID.randomUUID();
		this.timestamp = new Date(System.currentTimeMillis());
		this.product = product;
		this.amount = amount;
		
		if(causality != null)
			this.causality.addAll(causality);
	}
	
	/**
	 * Get all stored causality entries
	 * 
	 * @return a deep copy of the causality ArrayList Collection
	 * */
	public ArrayList<UUID> getCausality() {
		
		ArrayList<UUID> rCausality = new ArrayList<UUID>();
		
		for(UUID id: this.causality){
			rCausality.add(id);
		}
		
		return rCausality;
	}

	public String getProduct() {
		return product;
	}
	
	public void setProduct(String product) {
		this.product = product;
	}

	public int getAmount() {
		return amount;
	}
	
	public void setAmount(int amount) {
		this.amount = amount;
	}
	
	public UUID getId() {
		return this.id;
	}
	
	public Date getTimestamp() {
		return timestamp;
	}

	public void setId(UUID id) {
		this.id = id;
	}

	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}
}
